package com.changgou;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;


import java.util.Calendar;
import java.util.Date;

public class test {


    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE,+1 );
        Date time = calendar.getTime();
        JwtBuilder jwtBuilder = Jwts.builder()
                .setId("1")
                .setSubject("黑马程序员")
                .setIssuedAt(new Date())
   //             .setExpiration(time)
                .claim("roles","admin" )
                .claim("company","itheima" )
                .signWith(SignatureAlgorithm.HS256, "itheima");
        String compact = jwtBuilder.compact();
        System.out.println(compact);

        //解析
        Claims claims = Jwts.parser().setSigningKey("itheima").parseClaimsJws(compact).getBody();
        System.out.println(claims);
    }

}
